home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15382 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: ccshst05.cs.uoguelph.ca!ccshst01!thay
  2. From: thay@uoguelph.ca (Toby K Hay)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: help rand !
  5. Date: 18 Apr 1996 17:53:58 GMT
  6. Organization: University of Guelph
  7. Distribution: world
  8. Message-ID: <4l5vjm$5lj@ccshst05.uoguelph.ca>
  9. References: <4l5d75$mes@usenetp1.news.prodigy.com> <4l5fj4$1ehs@serra.unipi.it>
  10. NNTP-Posting-Host: ccshst01.uoguelph.ca
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Maurizio Loreti (loreti@mxsld2.pd.infn.it) wrote:
  14. : In article <4l5d75$mes@usenetp1.news.prodigy.com>, UNCK19A@prodigy.com (Thomas Furka) writes:
  15. : >I AM WRITING A PROGRAM FOR SCHOOL THAT PICKS 12 RANDOM NUMBERS. COULD 
  16. : >SOME ONE PLEASE HELP ME SO THAT I DON'T GET ANY DUPLICATES. I AM PICKING 
  17. : >FROM THE COMPUTER CLOCK(<TIME.H> USING SRAND.
  18.  
  19. : Don't shout; we are not blind.
  20. This is a disguised request to use upper case in only the usual places.
  21.  
  22. 1) Use srand() only once to initialize the sequence of random numbers - 
  23. use rand() to get the random numbers.
  24.  
  25. 2) To avoid duplicates in a set of 12 numbers simply check that each 
  26. new one isn't already in the list.  Since the range of random number 
  27. returned by rand() is 0 to at least 30,000 on most systems you're
  28. unlikely get any duplicates in the first 12.
  29.  
  30. 3) If this isn't what you meant (as seems likely) feel free to send me a 
  31. note with a clearer question.
  32.  
  33. Toby Hay    thay@uoguelph
  34.